﻿@model Phatent.Model.Pages.PageModel


<div class="GeneralEdit" id="fmPage">
    <ul>
        <li>
            <label for="ddlEditCase">栏目：</label>
            <select id="ddlEditCase" style="width:260px"></select>
        </li>
        <li>
            <label for="txtTitle">标题：</label>
            <input type="text" class="k-textbox" id="txtTitle" name="title" value="@Model.Title" pattern=".{2,}" required validationMessage="请输入标题" />
            <span class="k-invalid-msg" data-for="txtTitle"></span>
        </li>
        <li>
            <label for="txtAbbreviation">节略语：</label>
            <input type="text" class="k-textbox" id="txtAbbreviation" name="mobile" value="@Model.Abbreviation" />
        </li>
        <li>
            <label for="txtTitle">英文标题：</label>
            <input type="text" class="k-textbox" id="txtETitle" name="etitle" value="@Model.ETitle" pattern=".{2,}" required validationMessage="请输入英文标题" />
            <span class="k-invalid-msg" data-for="txtETitle"></span>
        </li>
        <li>
            <label for="txtAbbreviation">英文节略：</label>
            <input type="text" class="k-textbox" id="txtEAbbreviation" name="mobile" value="@Model.EAbbreviation" />
        </li>
        <li>
            <label for="txtThumbnail">缩略图：</label>
            <input type="text" class="k-textbox" id="txtThumbnail" name="thumbnail" value="@Model.Thumbnail" />
        </li>
        <li>
            <label for="txtPindex">排序号：</label>
            <input type="number" class="k-textbox" id="txtPindex" name="address" value="@Model.Pindex" min="0" />
        </li>
        
        <li>
            <label for="ddlPageType">类型：</label>
            <select id="ddlPageType">
                <option value="1" @(Model.PageType == 1 ? "selected='selected'" : "")>普通</option>
                <option value="2" @(Model.PageType == 2 ? "selected='selected'" : "")>特殊</option>
            </select>
        </li>
        <li class="editButtons">
            <button id="btnSavePage" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="save_customer">
    $("#ddlPageType").kendoDropDownList();
    $("#ddlEditCase").kendoDropDownList({
        dataTextField: "CaseName",
        template: "[#=ParentCase.CaseName#] #=CaseName#",
        dataValueField: "ID",
        dataSource: Whale.dataSource({
            url: "/Admin/Page/GetCases",
            getParameters: function () {
                return {
                    onlySubCase: true,
                    getParent: true
                }
            }
        }),
        dataBound: function (e) {
            this.select(function (dataItem) {
                if (dataItem.ID == "@Model.CaseID")
                    return true;
            });
        }
    });

    $(function () {
        var validator = $("#fmPage").kendoValidator().data("kendoValidator");
        $("#btnSavePage").click(function (e) {
            if (validator.validate()) {
                var values = {
                    pageID: "@Model.ID",
                    caseID: $("#ddlEditCase").data("kendoDropDownList").value(),
                    title: $("#txtTitle").val(),
                    thumbnail: $("#txtThumbnail").val(),
                    pindex: $("#txtPindex").val(),
                    abbreviation: $("#txtAbbreviation").val(),
                    pageType: $("#ddlPageType").data("kendoDropDownList").value(),
                    etitle: $("#txtETitle").val(),
                    eabbreviation: $("#txtEAbbreviation").val(),
                };

                Whale.Remote.Operation({
                    url: "/Admin/Page/SavePage",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_pages").length > 0)
                            $("#grid_pages").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>
